package basic;

import flexibility.userData;
import flexibility.getQuery;

public class queries {
	String query;
	private int type; // type=0 --> write to DB, type=1 --> read form DB
	/*
	 * identifyQuery: in this method we assemble the SQL query.
	 */
	public String identifyQuery(userData msg) {
		
		setType(msg);
		
		getQuery GETquery = new getQuery();
		query = GETquery.query(Integer.parseInt(msg.getData(0).toString()));
		
		//Check if the action is to upload the file
		if (this.getType()==3){
					return query;
				}
		else{
			for (int i = 2; i < msg.getLength(); i++) {
				query = query.replaceFirst("xxx", msg.getData(i)
						.toString());
			}
			return query;
		}

	}
	
	private void setType(userData msg){
		type = Integer.parseInt(msg.getData(1).toString());
	}

	public int getType(){
		return type;
	}
}
